﻿//用于控制表单IFRAME切换
function selectdiv(ctrl)
{
    var IsIe = false;
    if ((navigator.userAgent.indexOf('MSIE') >= 0) && (navigator.userAgent.indexOf('Opera') < 0))
    {
        IsIe = true;
    }
    var inputs = IsIe ? document.all.tags("td") : document.getElementsByTagName("td");
    for (var i = 0; i < inputs.length; i++)
    {
        if (typeof (inputs[i].className) == "undefined")
        {
            continue;
        } else if (inputs[i].className.indexOf("tdselect") > -1 || inputs[i].className.indexOf("tdunselect") > -1)
        {
//            var unselect = getUnSelectCss(IsIe ? inputs[i].innerText : inputs[i].textContent);
            inputs[i].className = "tdunselect1";
            //var divctrl = document.getElementById("div_" + inputs[i].id);
            //if (typeof (divctrl) != "undefined") {
            //    document.getElementById("div_" + inputs[i].id).style.display = "none";
            //}
            continue;
        }
    }
//    var selectCss = getSelectCss(IsIe ? ctrl.innerText : ctrl.textContent);
    //    var d = new Date();
    ctrl.className = "tdselect1";
    if (ctrl.id == "td1")
    {
        document.getElementById("mainFrame").src = td1url; // + "&d=" + d.toString();
    } else if (ctrl.id == "td2")
    {
        document.getElementById("mainFrame").src = td2url;  //+ "&d=" + d.toString();
    } else if (ctrl.id == "td3")
    {
        document.getElementById("mainFrame").src = td3url;  //+ "&d=" + d.toString();
    } else if (ctrl.id == "td4")
    {
        document.getElementById("mainFrame").src = td4url;  // + "&d=" + d.toString();
    } else if (ctrl.id == "td5")
    {
        document.getElementById("mainFrame").src = td5url;  // + "&d=" + d.toString();
    } else if (ctrl.id == "td6")
    {
        document.getElementById("mainFrame").src = td6url;  // + "&d=" + d.toString();
    }
    //document.getElementById("div_" + ctrl.id).style.display = "block";
}
//用于控制表单IFRAME切换
function selectdivMutil(ctrl, tabDiv) {
    var inputs = document.getElementById(tabDiv).all.tags("td");
    for (var i = 0; i < inputs.length; i++) {
        if (typeof (inputs[i].className) == "undefined") {
            continue;
        } else if (inputs[i].className.indexOf("tdselect") > -1 || inputs[i].className.indexOf("tdunselect") > -1) {
            var unselect = getUnSelectCss(inputs[i].innerText);
            inputs[i].className = unselect;
            //var divctrl = document.getElementById("div_" + inputs[i].id);
            //if (typeof (divctrl) != "undefined") {
            //    document.getElementById("div_" + inputs[i].id).style.display = "none";
            //}
            continue;
        }
    }
    var selectCss = getSelectCss(ctrl.innerText);
    var d = new Date();
    ctrl.className = selectCss;
    if (ctrl.id == "td1") {
        document.getElementById(tabDiv + "_mainFrame").src = td1url;
    } else if (ctrl.id == "td2") {
        document.getElementById(tabDiv + "_mainFrame").src = td2url;
    } else if (ctrl.id == "td3") {
        document.getElementById(tabDiv + "_mainFrame").src = td3url;
    } else if (ctrl.id == "td4") {
        document.getElementById(tabDiv + "_mainFrame").src = td4url;
    } else if (ctrl.id == "td5") {
        document.getElementById(tabDiv + "_mainFrame").src = td5url;
    } else if (ctrl.id == "td6") {
        document.getElementById(tabDiv + "_mainFrame").src = td6url;
    } else if (ctrl.id == "td7") {
        document.getElementById(tabDiv + "_mainFrame").src = td7url;
    }
    //document.getElementById("div_" + ctrl.id).style.display = "block";
}


function getUnSelectCss(val)
{
    var unSelectCss = "";
    var SelectCss = "";
    var l = StringLength(val);
    if (l <= 12) //6个汉字
    {
        SelectCss = "tdselect1";
        unSelectCss = "tdunselect1";
    }
    else if (l <= 18)
    {
        SelectCss = "tdselect2";
        unSelectCss = "tdunselect2";
    }
    else if (l <= 24)
    {
        SelectCss = "tdselect3";
        unSelectCss = "tdunselect3";
    }
    else
    {
        SelectCss = "tdselect4";
        unSelectCss = "tdunselect4";
    }
    return unSelectCss;
}
function getSelectCss(val)
{
    var unSelectCss = "";
    var SelectCss = "";
    var l = StringLength(val);
    if (l <= 12) //6个汉字
    {
        SelectCss = "tdselect1";
        unSelectCss = "tdunselect1";
    }
    else if (l <= 18)
    {
        SelectCss = "tdselect2";
        unSelectCss = "tdunselect2";
    }
    else if (l <= 24)
    {
        SelectCss = "tdselect3";
        unSelectCss = "tdunselect3";
    }
    else
    {
        SelectCss = "tdselect4";
        unSelectCss = "tdunselect4";
    }
    return SelectCss;
}

function StringLength(strTemp)
{
    var i, sum;
    sum = 0;
    for (i = 0; i < strTemp.length; i++)
    {
        if ((strTemp.charCodeAt(i) >= 0) && (strTemp.charCodeAt(i) <= 255))
            sum = sum + 1;
        else
            sum = sum + 2;
    }

    return sum;
}   

function SetCwinHeight(obj) {

    var cwin = obj;
    if (document.getElementById) {
        if (cwin && !window.opera) {
            //alert(cwin.Document.body.scrollHeight);
        if (cwin.Document && cwin.Document.body.scrollHeight)
            //cwin.height = cwin.Document.body.scrollHeight;
                document.getElementById(obj.id).style.height=cwin.Document.body.scrollHeight+200;
                else
            if (cwin.contentDocument && cwin.contentDocument.body.offsetHeight)
                document.getElementById(obj.id).style.height = cwin.contentDocument.body.offsetHeight+200;
            
        }
    }
} 
